package drongo.model.propertys
{
	import drongo.model.core.IProperty;
	import drongo.model.core.IValue;
	import drongo.model.events.ModelEvent;
	import drongo.model.values.ArrayValue;
	import drongo.model.values.CollectionValue;
	
	public class ArrayProperty extends ArrayValue implements IProperty
	{
		private var key:String;
		public function ArrayProperty(key:String)
		{
			super();
			this.key=key;
		}
		
		public function GetKey():String{
			return this.key;
		}
		
		override protected function SendEvent(newValue:*, oldValue:*):void
		{
			if(this.hasEventListener(ModelEvent.VALUE_CHANGED)){
				this.dispatchEvent(ModelEvent.Create(ModelEvent.VALUE_CHANGED,oldValue,value,this.key));
			}
		}
		/**
		 * 判断某个子内容的某个属性相同则返回true
		 */
		public function containProperty(value:IProperty):Boolean{
			var item:IValue;
			for (var j:int = 0; j < this.length; j++) 
			{
				item=this.list[j];
				if(item is CollectionValue){
					var collValue:CollectionValue=item as CollectionValue;
					var property:IProperty=collValue.Get(value.GetKey());
					if(property.Equality(value)){
						return true;
					}
				}
			}
			return false;
		}
		
		override public function Equality(value:IValue):Boolean{
			if(!(value is ArrayProperty)){
				return false;
			}
			var property:IProperty=value as ArrayProperty;
			if(this.key!=property.GetKey()){
				return false;
			}
			return super.Equality(value);
		}
	}
}